package wrap.pages;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HealthTopics.java
 *
 * Created on Nov 21, 2009, 12:23:39 PM
 */

/**
 *
 * @author Lazlo
 */

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.beans.PropertyChangeListener;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import wrap.core.*;

public class DOB extends javax.swing.JPanel {

    /** Creates new form HealthTopics */
    public DOB() {
        initComponents();

        
        //add(dob1, java.awt.BorderLayout.CENTER);
//        JPanel pan = new JPanel();
//        pan.setLayout(new java.awt.BorderLayout());
//        pan.add(new JButton(), java.awt.BorderLayout.CENTER);
//        add(pan, java.awt.BorderLayout.CENTER);
//


    }

    private void init(){

        System.out.println("init");

        JComponent c = (JComponent)this.getParent();
        int mod = JComponent.WHEN_IN_FOCUSED_WINDOW;
        Object ShowDOB1 = "ShowDOB1";
        Object ShowDOB2 = "ShowDOB2";
        Object ShowDOB3 = "ShowDOB3";
        c.getInputMap(mod).put(KeyStroke.getKeyStroke("F1"), ShowDOB1);
        c.getInputMap(mod).put(KeyStroke.getKeyStroke("F2"), ShowDOB2);
        c.getInputMap(mod).put(KeyStroke.getKeyStroke("F3"), ShowDOB3);



//        JComponent c = this;
//        c.addKeyListener(new KeyListener(){
//
//            public void keyTyped(KeyEvent e) {
//                System.out.println(e);
//            }
//
//            public void keyPressed(KeyEvent e) {
//                System.out.println(e);
//            }
//
//            public void keyReleased(KeyEvent e) {
//                System.out.println(e);
//            }
//        });

        c.getActionMap().put(ShowDOB1, new AbstractAction(){
            public void actionPerformed(ActionEvent e) {
                
                System.out.println(1);
                switchPanel(1);
            }
        });
        c.getActionMap().put(ShowDOB2, new AbstractAction(){
            public void actionPerformed(ActionEvent e) {
                
                System.out.println(2);
                switchPanel(2);
            }
        });
        c.getActionMap().put(ShowDOB3, new AbstractAction(){
            public void actionPerformed(ActionEvent e) {
                
                System.out.println(3);
                switchPanel(3);
            }
        });


    }

    DOB1 dob1 = new DOB1();
    DOB2 dob2 = new DOB2();
    DOB3 dob3 = new DOB3();


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setFocusCycleRoot(true);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                formFocusLost(evt);
            }
        });
        addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                formAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
                formAncestorRemoved(evt);
            }
        });
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                formKeyTyped(evt);
            }
        });
        setLayout(new java.awt.BorderLayout());
    }// </editor-fold>//GEN-END:initComponents

    private void switchPanel(int i){
        //i = i + 10;
        System.out.println(i);
        this.removeAll();
        switch(i){
            case 2:
                this.add(dob2, java.awt.BorderLayout.CENTER);
                break;
            case 3:
                this.add(dob3, java.awt.BorderLayout.CENTER);
                break;
            default:
                //this.add(dob1, java.awt.BorderLayout.CENTER);
                add(new JButton(), java.awt.BorderLayout.CENTER);
                break;
        }
        this.validate();
        this.repaint();

        init();


    }

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        System.out.println(evt.getKeyChar());
    }//GEN-LAST:event_formKeyPressed

    private void formFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusLost
        // TODO add your handling code here:
        this.requestFocus();
        System.out.println("requestFocus");
    }//GEN-LAST:event_formFocusLost

    private void formKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyTyped
        // TODO add your handling code here:
        System.out.println("formKeyTyped");
        System.out.println(evt.getKeyChar());
    }//GEN-LAST:event_formKeyTyped

    private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
        // TODO add your handling code here:
        System.out.println("formAncestorAdded");
        System.out.println(this.getParent());
        //init();

        DOBHelper.helper.installPanel((JPanel)this.getParent());
    }//GEN-LAST:event_formAncestorAdded

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        System.out.println("formComponentShown");
    }//GEN-LAST:event_formComponentShown

    private void formAncestorRemoved(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorRemoved
        // TODO add your handling code here:
    }//GEN-LAST:event_formAncestorRemoved

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
